package com.test.pattern.state.after;

/**
 * @ClassName: Context
 * @description: 环境角色类
 * @author: Mr du
 * @create: 2024-03-12 21:50
 */
public class Context {

    //定义状态对象常量
    //开门状态，这时候电梯只能关闭
    public static final OpeningState OPENING_STATE = new OpeningState();

    //关闭状态，这时候电梯可以运行、停止和开门
    public static final CloseingState CLOSEING_STATE = new CloseingState();

    //停止状态，这时候电梯可以开门、运行
    public static final StopingState STOPING_STATE =new StopingState();

    //运行状态，这时候电梯只能停止
    public static final RuningState RUNING_STATE = new RuningState();

    private LiftState liftState;

    public LiftState getLiftState() {
        return liftState;
    }

    public void setLiftState(LiftState liftState) {
        this.liftState = liftState;
        //设置当前对象中的Context对象
        liftState.setContext(this);
    }

    public void open(){
        this.liftState.open();
    }

    public void close(){
        this.liftState.close();
    }

    public void stop(){
        this.liftState.stop();
    }

    public void run(){
        this.liftState.run();
    }
}
